home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-06-22 | 1.9 KB | 54 lines | [TEXT/CWIE] |
- // CQueue - a small utility class to allow queuing and dequeuing of objects
- // Add items to the end of the queue, and remove them from the front, one at a time
- // This is a generic queue that can be used without overriding for any reason.
- // Simply tell the object how big the elements etc are, and then feed it pointers
- // to your data.
-
- #ifndef __CFIFOQUEUE__
- #define __CFIFOQUEUE__
-
-
- #pragma once
-
- enum {
- kDefaultQueueSize = 10,
-
- kQueueAlreadyTooBig = 1 // This error says you can't shrink the queue size smaller
- // You already have more elements than that in the queue
- };
-
-
- class CFIFOQueue
- {
- Handle fQueueHead;
- long fQueueMaxElements; // This determines how much memory is allocated for the queue
- long fQueueElements; // How many elements we have in the queue currently
- long fQueueElementSize; // How big each element in the queue is
- Boolean fOnlyLongs; // This flag means we are cheating and taking the void* from
- // AddElement as a long, not a pointer to data. This can make
- // us MUCH faster for pointers, etc.
- Boolean fAutoExpand; // Can we grow the queue on need, or only when told?
-
- public:
- CFIFOQueue(Boolean autoExpand = true, Boolean onlyLongs = false);
- CFIFOQueue(long elementSize, long maxElements = kDefaultQueueSize,
- Boolean autoExpand = true, Boolean onlyLongs = false);
- virtual ~CFIFOQueue(void);
-
- OSErr SetMaxQueueSize(long maxElements); // Could return an error (-108, or QueueTooBig)
- long GetMaxQueueSize(void);
-
- long GetQueueElementSize(void);
-
- // these functions return FALSE if they failed in some way. GetFrontElement could
- // fail if the queue is empty.
- virtual Boolean AddElement(void *theData); // The address to take data from
- virtual Boolean GetFrontElement(void* theData);
-
- long GetQueueLength(void);
-
- protected:
- virtual void AddOneElementToQueue(void *theData); // Add without bounds check
- };
-
- #endif